package demo1;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LianBao
 * Date: 2024-03-16
 * Time: 11:36
 */
public class Test1 {

    public static void main(String[] args) {
        //自定义异常
        /*
        如果try catch捕获不了异常,最后会交给jvm处理
         */

        Scanner input = new Scanner(System.in);
        try {
            System.out.println("请输入密码");
            String password = input.nextLine();
            System.out.println("请输入用户名");
            String admin = input.nextLine();
            if (!password.equals("12345")) {
                throw new PasswordWrongException();
            }
            if (!admin.equals("wpre")) {
                throw new AdminWrongException();
            }
        } catch (PasswordWrongException e) {
            System.out.println("密码错误");
        } catch (AdminWrongException e) {
            System.out.println("用户名错误");
        } catch (Exception e) {
            System.out.println("捕获异常...");
        } finally {
            System.out.println("finally永远执行");
            input.close();
        }
    }

    public static void main1(String[] args) {
        try {
            int a = 10;
            int b = 0;
            int c = a / b;
            System.out.println(c);
        } catch (ArithmeticException e) {
            e.printStackTrace();
        } finally {
            System.out.println("finally永远都执行");
        }
    }

}
